package com.corpgovernment.travelstandard.impl;

import com.corpgovernment.api.organization.bo.SearchEmployeeInfoRequestBO;
import com.corpgovernment.api.organization.model.user.employee.OrgEmployeeVo;
import com.corpgovernment.api.travelstandard.bo.*;
import com.corpgovernment.api.travelstandard.enums.CarSwitchEnum;
import com.corpgovernment.api.travelstandard.enums.CarSwitchEnum.DatetimeSwitch;
import com.corpgovernment.api.travelstandard.enums.CarSwitchEnum.ModelSwitch;
import com.corpgovernment.api.travelstandard.enums.CarSwitchEnum.PriceSwitch;
import com.corpgovernment.api.travelstandard.enums.ControlTypeEnum;
import com.corpgovernment.api.travelstandard.enums.ReasonCodeTypeEnum;
import com.corpgovernment.api.travelstandard.enums.TravelStandardTypeEnum;
import com.corpgovernment.common.common.CorpBusinessException;
import com.corpgovernment.common.entity.db.BaseEntity;
import com.corpgovernment.common.enums.ExceptionCodeEnum;
import com.corpgovernment.organization.constant.OrganizationResponseCodeEnum;
import com.corpgovernment.organization.entity.db.MbPostInfo;
import com.corpgovernment.organization.service.IOrganizationEmployeeService;
import com.corpgovernment.travelstandard.constant.ServiceConstant;
import com.corpgovernment.travelstandard.convert.AirportTransferStandardConvert;
import com.corpgovernment.travelstandard.dto.AirportTransferStandardDTO;
import com.corpgovernment.travelstandard.entity.db.*;
import com.corpgovernment.travelstandard.loader.*;
import com.corpgovernment.travelstandard.vo.*;
import com.corpgovernment.travelstandard.vo.airport.*;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import com.ctrip.corp.obt.generic.utils.JsonUtils;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 接送机service类
 */
@Service
@Slf4j
public class AirportTransferStandardService extends TravelStandardBaseService{

	private final static String[] AIRPORT_TRANSFER_RC_TEMPS = {"AirportTransferRcCpTemp","AirportTransferRcCmTemp"};

	@Autowired
	private MbPostLoader postLoader;
	@Autowired
	private IOrganizationEmployeeService employeeService;
	@Autowired
	private TravelStandardPostLoader travelStandardPostLoader;
	@Autowired
	private MbTravelStandardCarModelLoader travelStandardCarModelLoader;
	@Autowired
	private AirportTransferStandardConvert airportTransferStandardConvert;
	@Autowired
	private MbTravelStandardReasonCodeLoader travelStandardReasonCodeLoader;
	@Autowired
	private MbTravelStandardAirportTransferLoader travelStandardAirportTransferLoader;
	@Autowired
	private MbTravelStandCarCityService mbTravelStandCarCityService;

	/**
	 * 新增初始化接送机差标
	 *
	 * @param request
	 * @return
	 */
	@Transactional(rollbackFor = RuntimeException.class)
	public InitStandardResponseVO<AirportTransferControlVO> init(InitStandardRequestVO request) {
		String title = request.getTitle();
		String orgId = request.getOrgId();

		AirportTransferStandardDTO airportTransferStandard = AirportTransferStandardDTO.create(
				orgId,
				title,
				ModelSwitch.N.getCode(),
				ControlTypeEnum.F.getCode(),
				PriceSwitch.N.getCode(),
				BigDecimal.valueOf(100),
				ControlTypeEnum.F.getCode(),
				DatetimeSwitch.N.getCode(),
				ControlTypeEnum.F.getCode(),
				CarSwitchEnum.CarCitySwitch.N.getCode(),
				ControlTypeEnum.F.getCode());
		MbTravelStandardAirportTransfer travelStandardAirportTransfer = airportTransferStandardConvert.convertToTravelStandardCar(airportTransferStandard);
        travelStandardAirportTransfer.setProductSwitch("E");
		Long tsId = travelStandardAirportTransferLoader.save(travelStandardAirportTransfer);
		if (tsId == null) {
			throw new CorpBusinessException(OrganizationResponseCodeEnum.TRAVEL_STAND_IS_NULL);
		}
		List<MbTravelstandCarModel> travelStandardCarModelList = airportTransferStandardConvert.convertTravelStandardCarModel(tsId);
		travelStandardCarModelLoader.batchSave(travelStandardCarModelList);
		//对应RC
		//从apollo获取默认RC并插入
		insertTravelstandReasonCode(AIRPORT_TRANSFER_RC_TEMPS, tsId);

		List<MbTravelstandReasonCode> travelStandardReasonCodes = travelStandardReasonCodeLoader.selectByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		//获取相关车型信息
		List<MbTravelstandCarModel> travelStandardCarModels = travelStandardCarModelLoader.selectByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		//获取相关城市信息
		List<MbTravelStandCarCity> travelStandCarCities = mbTravelStandCarCityService.selectByTsid(String.valueOf(tsId), TravelStandardTypeEnum.AirportTransfer.getCode());
		return InitStandardResponseVO.create(airportTransferStandardConvert.convertToControl(travelStandardAirportTransfer, null, travelStandardReasonCodes, travelStandardCarModels, travelStandCarCities));
	}

	public UpdateNameResponseVO updateStandardName(UpdateNameRequestVO request) {
		Long id = request.getId();
		MbTravelStandardAirportTransfer travelStandardAirportTransfer = travelStandardAirportTransferLoader.selectById(id);
		if (travelStandardAirportTransfer == null) {
			throw new CorpBusinessException(OrganizationResponseCodeEnum.TRAVEL_STAND_IS_NULL);
		}
		travelStandardAirportTransfer.setName(request.getTitle());
		travelStandardAirportTransferLoader.updateById(travelStandardAirportTransfer);
		return UpdateNameResponseVO.success();
	}

	@Transactional(rollbackFor = RuntimeException.class)
	public SaveAirportTransferControlResponseVO save(SaveAirportTransferControlRequestVO request) {
		// 参数校验
		checkRequestParam(request);
		Long tsId = request.getId();
		MbTravelStandardAirportTransfer travelStandardAirportTransfer = travelStandardAirportTransferLoader.selectById(tsId);
		if (travelStandardAirportTransfer == null) {
			throw new CorpBusinessException(OrganizationResponseCodeEnum.TRAVEL_STAND_IS_NULL);
		}
		MbTravelStandardAirportTransfer nowTravelStandardAirportTransfer = airportTransferStandardConvert.convertToNowTravelStandard(travelStandardAirportTransfer, request);
		log.info("更新后的差标：{}", JsonUtils.toJsonString(nowTravelStandardAirportTransfer));
        nowTravelStandardAirportTransfer.setProductSwitch(request.getProductSwitch());
		int count = travelStandardAirportTransferLoader.updateById(nowTravelStandardAirportTransfer);
		//更新差标属性
		if (count < 1) {
			throw new CorpBusinessException(OrganizationResponseCodeEnum.TRAVEL_STAND_UPDATE_FAILED);
		}
		travelStandardReasonCodeLoader.deleteByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		//删除车型信息
		travelStandardCarModelLoader.deleteByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		//删除旧职位
		travelStandardPostLoader.deleteByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		//删除旧城市
		mbTravelStandCarCityService.delByTsid(String.valueOf(tsId), TravelStandardTypeEnum.AirportTransfer.getCode());
		//新增价格RC
		this.savePriceReasonCode(request);
		//新增车型RC
		this.saveModelReasonCode(request);
		//新增城市RC
		this.saveCityReasonCode(request);
		//新增车型
		this.saveCarModel(request);
		//新增城市
		this.saveCarCity(request);
		//新增职位
		this.saveTravelStandardPost(request, travelStandardAirportTransfer);
		return SaveAirportTransferControlResponseVO.success();
	}

	private void checkRequestParam(SaveAirportTransferControlRequestVO requestParam) {
		if (requestParam == null) {
			return;
		}
		// 填入的金额不能超过最大值
		if (requestParam.getPriceControl() != null
				&& requestParam.getPriceControl().getPriceCeiling().compareTo(new BigDecimal(ServiceConstant.UPPER_LIMIT_PRICE_OF_TRAVEL_STANDARD)) > 0) {
			throw new CorpBusinessException(OrganizationResponseCodeEnum.UPPER_LIMIT_PRICE_OF_TRAVEL_STANDARD);
		}
	}

	private void saveCarCity(SaveAirportTransferControlRequestVO request) {
		Long tsId = request.getId();
		CityControl cityControl = Optional.ofNullable(request.getCityControl()).orElse(new CityControl());
		if (Objects.nonNull(cityControl.getCarCityControlVo())) {
			mbTravelStandCarCityService.delByTsid(String.valueOf(tsId), TravelStandardTypeEnum.AirportTransfer.getCode());
			List<CarCityVo> cityVos = cityControl.getCarCityControlVo().getCityVos();
			List<MbTravelStandCarCity> carCityList = new ArrayList<>();
			if (!CollectionUtils.isEmpty(cityVos)) {
				for (CarCityVo item : cityVos) {
					MbTravelStandCarCity mbTravelStandCarCity = new MbTravelStandCarCity();
					BeanUtils.copyProperties(item, mbTravelStandCarCity);
					mbTravelStandCarCity.setControlType(cityControl.getCarCityControlVo().getControlType());
					mbTravelStandCarCity.setTsid(tsId);
					mbTravelStandCarCity.setTsType(TravelStandardTypeEnum.AirportTransfer.getCode());
					carCityList.add(mbTravelStandCarCity);
				}
			}
			else {
				MbTravelStandCarCity mbTravelStandCarCity = new MbTravelStandCarCity();
				mbTravelStandCarCity.setControlType(cityControl.getCarCityControlVo().getControlType());
				mbTravelStandCarCity.setTsid(tsId);
				mbTravelStandCarCity.setTsType(TravelStandardTypeEnum.AirportTransfer.getCode());
				carCityList.add(mbTravelStandCarCity);
			}
			mbTravelStandCarCityService.saveBatch(carCityList);
		}

	}

	private void saveCityReasonCode(SaveAirportTransferControlRequestVO request) {
		Long tsId = request.getId();
		CityControl cityControl = Optional.ofNullable(request.getCityControl()).orElse(new CityControl());
		List<NodeVO> carCityRcCheckList = cityControl.getCarCityRcCheckList();
		if(CollectionUtils.isEmpty(carCityRcCheckList)) {
			return;
		}
		//删除管控相关RC
		//插入所有RC
		List<MbTravelstandReasonCode> rcList = new ArrayList<>();
		for (NodeVO node : carCityRcCheckList) {
			MbTravelstandReasonCode entity = new MbTravelstandReasonCode();
			entity.setTsRcType(ReasonCodeTypeEnum.CC.getCode());
			entity.setTsType(TravelStandardTypeEnum.AirportTransfer.getCode());
			entity.setTsId(tsId);
			entity.setName(node.getName());
			entity.setIsChecked(node.getIsChecked());
			entity.setDatachangeCreatetime(new Date());
			entity.setDatachangeLasttime(new Date());
			rcList.add(entity);
		}
		travelStandardReasonCodeLoader.batchSave(rcList);
	}

	private void saveTravelStandardPost(SaveAirportTransferControlRequestVO request, MbTravelStandardAirportTransfer travelStandardAirportTransfer) {
		String jobScopeId = request.getJobScopeId();
		String orgId = request.getOrgId();
		Long tsId = request.getId();
		String[] jobIds = jobScopeId.split(",");
		List<TravelStandardPost> postList = Arrays.stream(jobIds).map(jobId -> {
			TravelStandardPost travelStandardPost = new TravelStandardPost();
			travelStandardPost.setPostid(Long.valueOf(jobId));
			travelStandardPost.setOrgid(orgId);
			travelStandardPost.setTsid(tsId);
			travelStandardPost.setTstype(TravelStandardTypeEnum.AirportTransfer.getCode());
			travelStandardPost.setTsname(travelStandardAirportTransfer.getName());
			travelStandardPost.setDatachangeCreatetime(new Date());
			travelStandardPost.setDatachangeLasttime(new Date());
			return travelStandardPost;
		}).collect(Collectors.toList());
		travelStandardPostLoader.batchSave(postList);
	}

	/**
	 * 保存车型
	 *
	 * @param request
	 */
	private void saveCarModel(SaveAirportTransferControlRequestVO request) {
		Long tsId = request.getId();
		ModelControlVO modelControl = request.getModelControl();
		List<NodeVO> searNodes = modelControl.getCarTypeList();
		List<MbTravelstandCarModel> carModels = searNodes.stream().filter(NodeVO::getIsChecked).map(e -> {
			MbTravelstandCarModel carModel = new MbTravelstandCarModel();
			carModel.setTsCarId(tsId);
			carModel.setModelName(e.getName());
			carModel.setModelCode(e.getCode());
			carModel.setTsType(TravelStandardTypeEnum.AirportTransfer.getCode());
			carModel.setDatachangeLasttime(new Date());
			carModel.setDatachangeCreatetime(new Date());
			return carModel;
		}).collect(Collectors.toList());
		travelStandardCarModelLoader.batchSave(carModels);
	}

	/**
	 * 更新车型rc
	 *
	 * @param request
	 */
	private void saveModelReasonCode(SaveAirportTransferControlRequestVO request) {
		Long tsId = request.getId();
		ModelControlVO modelControl = request.getModelControl();
		List<NodeVO> modelRcCheckList = modelControl.getModelRcCheckList();
		//删除管控相关RC
		//插入所有RC
		List<MbTravelstandReasonCode> rcList = new ArrayList<>();
		for (NodeVO node : modelRcCheckList) {
			MbTravelstandReasonCode entity = new MbTravelstandReasonCode();
			entity.setTsRcType(ReasonCodeTypeEnum.CM.getCode());
			entity.setTsType(TravelStandardTypeEnum.AirportTransfer.getCode());
			entity.setTsId(tsId);
			entity.setName(node.getName());
			entity.setIsChecked(node.getIsChecked());
			entity.setDatachangeCreatetime(new Date());
			entity.setDatachangeLasttime(new Date());
			rcList.add(entity);
		}
		travelStandardReasonCodeLoader.batchSave(rcList);
	}

	/**
	 * 更新价格rc
	 *
	 * @param request
	 */
	private void savePriceReasonCode(SaveAirportTransferControlRequestVO request) {
		Long tsId = request.getId();
		PriceControlVO priceControl = request.getPriceControl();
		List<NodeVO> priceRCCheckList = priceControl.getPriceRcCheckList();
		//删除管控相关RC
		//插入所有RC
		List<MbTravelstandReasonCode> rcList = new ArrayList<>();
		for (NodeVO node : priceRCCheckList) {
			MbTravelstandReasonCode entity = new MbTravelstandReasonCode();
			entity.setTsRcType(ReasonCodeTypeEnum.CP.getCode());
			entity.setTsType(TravelStandardTypeEnum.AirportTransfer.getCode());
			entity.setTsId(tsId);
			entity.setName(node.getName());
			entity.setIsChecked(node.getIsChecked());
			entity.setDatachangeLasttime(new Date());
			entity.setDatachangeCreatetime(new Date());
			rcList.add(entity);
		}
		travelStandardReasonCodeLoader.batchSave(rcList);
	}

	public GetAirportTransferStandardResponseVO getStandard(GetAirportTransferStandardRequestVO request) {
		String orgId = request.getOrgId();
		// 查询接送机差标
		List<MbTravelStandardAirportTransfer> travelStandardAirportTransfers = travelStandardAirportTransferLoader.selectByOrgId(orgId);
		if (CollectionUtils.isEmpty(travelStandardAirportTransfers)) {
			List<MbPostInfo> postInfos = postLoader.selectByOrgId(orgId);
			List<PostVO> postVos = airportTransferStandardConvert.convertToPostVO(postInfos);
			return GetAirportTransferStandardResponseVO.create(Lists.newArrayList(), postVos, Lists.newArrayList());
		}
		// 查询接送机差标职级
		List<TravelStandardPost> travelStandardPosts = travelStandardPostLoader.selectByOrgIdAndType(orgId, TravelStandardTypeEnum.AirportTransfer.getCode());
		// 查询接送机职级
		List<MbPostInfo> postInfos = postLoader.selectByOrgId(orgId);
		List<String> jobScopeList = travelStandardPosts.stream().map(TravelStandardPost::getPostid).map(String::valueOf).collect(Collectors.toList());
		List<Long> tsIds = travelStandardAirportTransfers.stream().map(BaseEntity::getId).collect(Collectors.toList());
		List<MbTravelstandReasonCode> travelStandardReasonCodes = travelStandardReasonCodeLoader.selectByTsIds(tsIds, TravelStandardTypeEnum.AirportTransfer.getCode());
		List<MbTravelstandCarModel> travelStandardCarModels = travelStandardCarModelLoader.selectByTsIds(tsIds, TravelStandardTypeEnum.AirportTransfer.getCode());
		List<MbTravelStandCarCity> mbTravelStandCarCities = mbTravelStandCarCityService.selectByTsids(tsIds, TravelStandardTypeEnum.AirportTransfer.getCode());
		List<AirportTransferControlVO> carControlList = airportTransferStandardConvert.convertToControls(travelStandardAirportTransfers, travelStandardPosts, travelStandardReasonCodes, travelStandardCarModels, mbTravelStandCarCities);
		List<PostVO> postVos = airportTransferStandardConvert.convertToPostVO(postInfos);
		return GetAirportTransferStandardResponseVO.create(carControlList, postVos, jobScopeList);
	}

	public UpdateReasonCodeResponseVO updateRc(UpdateReasonCodeRequestVO request) {
		Long tsId = request.getId();
		MbTravelStandardAirportTransfer travelStandardAirportTransfer = travelStandardAirportTransferLoader.selectById(tsId);
		if (travelStandardAirportTransfer == null) {
			throw new CorpBusinessException(ExceptionCodeEnum.Alert, "差标不存在");
		}
		String rcType = request.getRcType();
		//删除管控相关RC
		travelStandardReasonCodeLoader.deleteByTsIdAndRcType(tsId, rcType);
		//插入所有RC
		List<MbTravelstandReasonCode> reasonCodes = request.getRcList().stream().map(e -> {
			MbTravelstandReasonCode entity = new MbTravelstandReasonCode();
			entity.setTsRcType(request.getRcType());
			entity.setTsType(TravelStandardTypeEnum.AirportTransfer.getCode());
			entity.setTsId(tsId);
			entity.setName(e.getName());
			entity.setIsChecked(e.getIsChecked());
			entity.setDatachangeCreatetime(new Date());
			entity.setDatachangeLasttime(new Date());
			return entity;
		}).collect(Collectors.toList());
		travelStandardReasonCodeLoader.batchSave(reasonCodes);
		return UpdateReasonCodeResponseVO.success();
	}

	/**
	 * 删除差标
	 *
	 * @param request
	 * @return
	 */
	@Transactional(rollbackFor = RuntimeException.class)
	public DeleteStandardResponseVO delete(DeleteStandardRequestVO request) {
		Long tsId = request.getId();
		MbTravelStandardAirportTransfer travelStandardAirportTransfer = travelStandardAirportTransferLoader.selectById(tsId);
		if (travelStandardAirportTransfer == null) {
			throw new CorpBusinessException(ExceptionCodeEnum.Alert, "差标不存在");
		}
		//删除差标
		travelStandardAirportTransferLoader.deleteById(tsId);
		//删除相关RC
		travelStandardReasonCodeLoader.deleteByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		//删除相关车型
		travelStandardCarModelLoader.deleteByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		//删除相关职位关联
		travelStandardPostLoader.deleteByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		//删除相关城市关联
		mbTravelStandCarCityService.delByTsid(String.valueOf(tsId), TravelStandardTypeEnum.AirportTransfer.getCode());
		return DeleteStandardResponseVO.success();
	}

	public AirportTransferStandardResponseBO getTravelStandard(AirportTransferStandardRequestBO request) {
		Long postId = null;
		if (Objects.nonNull(request.getPostId()) && request.getPostId() > 0){
			postId = request.getPostId();
		} else {
			OrgEmployeeVo orgEmployee = employeeService.searchEmployeeInfo(SearchEmployeeInfoRequestBO.create(request.getUid(), request.getOrgId()));
			if (orgEmployee == null) {
				throw new CorpBusinessException(OrganizationResponseCodeEnum.USER_INFO_DONT_EXISTS);
			}
			postId = orgEmployee.getPostId();
		}

		List<TravelStandardPost> travelStandardPosts = travelStandardPostLoader.selectByPostIdAndType(postId, TravelStandardTypeEnum.AirportTransfer.getCode());
		log.info("travelStandardPostLoader.selectByPostIdAndType,postId:{},travelStandardPosts:{}",postId,JsonUtils.toJsonString(travelStandardPosts));
		List<AirportTransferDescBO> airportTransferDescList = Lists.newArrayList();
		if (CollectionUtils.isEmpty(travelStandardPosts)) {
			AirportTransferDescBO priceDesc = new AirportTransferDescBO();
			priceDesc.setTitle("可订价格");
			priceDesc.setContent("不限");
			airportTransferDescList.add(priceDesc);
			AirportTransferDescBO carDesc = new AirportTransferDescBO();
			carDesc.setTitle("可选车型");
			carDesc.setContent("不限");
			airportTransferDescList.add(carDesc);
			return AirportTransferStandardResponseBO.create(airportTransferDescList);
		}

		TravelStandardPost post = travelStandardPosts.get(0);
		Long tsId = post.getTsid();
		MbTravelStandardAirportTransfer travelStandardAirportTransfer = travelStandardAirportTransferLoader.selectById(tsId);

		List<MbTravelstandReasonCode> reasonCodes = travelStandardReasonCodeLoader.selectByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		log.info("travelStandardReasonCodeLoader.selectByTsIdAndType,tsId:{},reasonCodes:{}",tsId,JsonUtils.toJsonString(reasonCodes));
		List<MbTravelstandCarModel> carModels = travelStandardCarModelLoader.selectByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		log.info("travelStandardCarModelLoader.selectByTsIdAndType,tsId:{},carModels:{}",tsId,JsonUtils.toJsonString(carModels));
		List<MbTravelStandCarCity> carCities = mbTravelStandCarCityService.selectByTsid(String.valueOf(tsId), TravelStandardTypeEnum.AirportTransfer.getCode());
		log.info("mbTravelStandCarCityService.selectByTsid,tsId:{},carCities:{}",tsId,JsonUtils.toJsonString(carCities));
		AirportTransferControlVO airportTransferControl = airportTransferStandardConvert.convertToControl(travelStandardAirportTransfer, travelStandardPosts, reasonCodes, carModels, carCities);
		log.info("airportTransferStandardConvert.convertToControl,airportTransferControl:{}",JsonUtils.toJsonString(airportTransferControl));

		ModelControlVO modelControl = airportTransferControl.getModelControl();
		PriceControlVO priceControl = airportTransferControl.getPriceControl();
		CityControl cityControl = airportTransferControl.getCityControl();

		List<AirportTransferDescBO> descList = new ArrayList<>();
		// 首先处理产线管控
        if ("N".equals(airportTransferControl.getProductSwitch())){
            AirportTransferDescBO desc = new AirportTransferDescBO();
            desc.setTitle("产线管控");
            desc.setContent("禁止预订");
            descList.add(desc);
            return AirportTransferStandardResponseBO.create(descList);
        }
		if (Objects.equals(modelControl.getStatus(), "E")) {
			AirportTransferDescBO desc = new AirportTransferDescBO();
			List<NodeVO> carTypeList = Optional.ofNullable(modelControl.getCarTypeList()).orElse(new ArrayList<>());
			String content = carTypeList.stream().filter(NodeVO::getIsChecked).map(NodeVO::getName).collect(Collectors.joining("、"));
			desc.setTitle("可选车型");
			desc.setContent(content);
			descList.add(desc);
		} else {
			AirportTransferDescBO desc = new AirportTransferDescBO();
			desc.setTitle("可选车型");
			desc.setContent("不限");
			descList.add(desc);
		}
		if (Objects.equals(priceControl.getStatus(), "E")) {
			BigDecimal priceFloor = priceControl.getPriceFloor()  == null ? BigDecimal.ZERO : priceControl.getPriceFloor();
			BigDecimal priceCeiling = priceControl.getPriceCeiling();
			AirportTransferDescBO desc = new AirportTransferDescBO();
			desc.setTitle("可订价格");
			if (BigDecimal.ZERO.compareTo(priceFloor) > 0) {
				desc.setContent("￥" + priceCeiling + "及以下");
			} else {
				desc.setContent("￥" + priceFloor + "-￥" + priceCeiling);
			}
			descList.add(desc);
		} else {
			AirportTransferDescBO desc = new AirportTransferDescBO();
			desc.setTitle("可订价格");
			desc.setContent("不限");
			descList.add(desc);
		}
		if (carCities != null && Objects.nonNull(cityControl) && Objects.equals(cityControl.getStatus(), "E")) {
			CarCityControlVo carCityControlVo = cityControl.getCarCityControlVo();
			if (0 == carCityControlVo.getControlType()) {
				AirportTransferDescBO desc = new AirportTransferDescBO();
				desc.setTitle("可订城市");
				desc.setContent("不限");
				descList.add(desc);
			}
			if (1 == carCityControlVo.getControlType()) {
				StringBuffer sb = new StringBuffer();
				List<CarCityVo> cityVos = carCityControlVo.getCityVos();
				for (CarCityVo cityVo : cityVos) {
					sb.append(cityVo.getCityName()).append(",");
				}
				AirportTransferDescBO desc = new AirportTransferDescBO();
				desc.setTitle("可订城市");
				desc.setContent(sb.deleteCharAt(sb.length() - 1).toString());
				descList.add(desc);
			}
			if (2 == carCityControlVo.getControlType()) {
				StringBuffer sb = new StringBuffer();
				List<CarCityVo> cityVos = carCityControlVo.getCityVos();
				for (CarCityVo cityVo : cityVos) {
					sb.append(cityVo.getCityName()).append(",");
				}
				AirportTransferDescBO desc = new AirportTransferDescBO();
				desc.setTitle("不可订城市");
				desc.setContent(sb.deleteCharAt(sb.length() - 1).toString());
				descList.add(desc);
			}
		}
		else {
			AirportTransferDescBO desc = new AirportTransferDescBO();
			desc.setTitle("可订城市");
			desc.setContent("不限");
			descList.add(desc);
		}

		return AirportTransferStandardResponseBO.create(descList);
	}

	public AirportTransferStandardDetailResponseBO getTravelStandardDetail(AirportTransferStandardDetailRequestBO request) {
		Long postId = null;
		if (Objects.nonNull(request.getPostId()) && request.getPostId() > 0){
			postId = request.getPostId();
		} else {
			OrgEmployeeVo orgEmployeeVo = employeeService.searchEmployeeInfo(SearchEmployeeInfoRequestBO.create(request.getUid(), request.getOrgId()));
			if (orgEmployeeVo == null) {
				throw new CorpBusinessException(OrganizationResponseCodeEnum.USER_INFO_DONT_EXISTS);
			}
			postId = orgEmployeeVo.getPostId();
		}
		//获取相关职位
		List<TravelStandardPost> travelStandardPosts = travelStandardPostLoader.selectByPostIdAndType(postId, TravelStandardTypeEnum.AirportTransfer.getCode());
		log.info("获取相关职位,postId:{},travelStandardPosts:{}",postId,JsonUtils.toJsonString(travelStandardPosts));
		if (CollectionUtils.isEmpty(travelStandardPosts)) {
			return AirportTransferStandardDetailResponseBO.isEmpty();
		}
		TravelStandardPost post = travelStandardPosts.get(0);
		Long tsId = post.getTsid();
		// 查询接送机差标
		MbTravelStandardAirportTransfer travelStandardAirportTransfer = travelStandardAirportTransferLoader.selectById(tsId);
		log.info("查询接送机差标,tsId:{},travelStandardAirportTransfer:{}",tsId,JsonUtils.toJsonString(travelStandardAirportTransfer));
		//获取相关rc
		List<MbTravelstandReasonCode> reasonCodes = travelStandardReasonCodeLoader.selectByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		log.info("获取相关rc,tsId:{},reasonCodes:{}",tsId,JsonUtils.toJsonString(reasonCodes));
		//获取相关车型信息
		List<MbTravelstandCarModel> carModels = travelStandardCarModelLoader.selectByTsIdAndType(tsId, TravelStandardTypeEnum.AirportTransfer.getCode());
		log.info("获取相关车型信息,tsId:{},carModels:{}",tsId,JsonUtils.toJsonString(carModels));
		//获取相关城市
		List<MbTravelStandCarCity> carCities = mbTravelStandCarCityService.selectByTsid(String.valueOf(tsId), TravelStandardTypeEnum.AirportTransfer.getCode());
		log.info("获取相关城市,tsId:{},carCities:{}",tsId,JsonUtils.toJsonString(carCities));
		AirportTransferControlVO airportTransferControlVO = airportTransferStandardConvert.convertToControl(travelStandardAirportTransfer, travelStandardPosts, reasonCodes, carModels, carCities);
		log.info("获取相关城市,tsId:{},airportTransferControlVO:{}",tsId,JsonUtils.toJsonString(airportTransferControlVO));
		return airportTransferStandardConvert.convertToDetailBO(airportTransferControlVO);
	}
}
